package com.wbcs.system.tags.component;

import java.io.IOException;

import javax.servlet.jsp.JspException;

import com.wbcs.exception.WbcsRuntimeException;
import com.wbcs.system.assistant.TagAssistant;
import com.wbcs.system.component.application.report.abstractreport.AbsReportType;

public class TitleTag extends AbsComponentTag
{
    private static final long serialVersionUID=-3266691866541279150L;

    private String type;

    private String top;

    public void setType(String type)
    {
        this.type=type;
    }

    public void setTop(String top)
    {
        this.top=top;
    }

    @Override
	public int doMyStartTag() throws JspException,IOException
    {
        if(this.displayComponentObj==null) return SKIP_BODY;
        if(!(this.displayComponentObj instanceof AbsReportType))
        {
            throw new WbcsRuntimeException("组件"+this.displayComponentObj.getConfigBean().getPath()+"不是报表，不能调用<wx:title/>显示其标题部分");
        }
        if(type!=null)
        {
            type=type.toLowerCase().trim();
            if(!type.equals("")&&!type.equals("title")&&!type.equals("subtitle"))
            {
                throw new JspException("<title/>标签中type属性指定的值只能是title或subtitle");
            }
        }
        return EVAL_BODY_INCLUDE;
    }

    @Override
	public int doMyEndTag() throws JspException,IOException
    {
        if(this.displayComponentObj==null) return EVAL_PAGE;
        TagAssistant.getInstance().printlnTag(out,rrequest,
                TagAssistant.getInstance().getTitleDisplayValue((AbsReportType)this.displayComponentObj,type,top));
        return EVAL_PAGE;
    }
}
